package src.leetcode.greedy.simple_0860;

public class lemonadeChange {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.lemonadeChange(new int[]{5,5,10,20,5,5,5,5,5,5,5,5,5,10,5,5,20,5,20,5}));
    }
}

class Solution {
    public boolean lemonadeChange(int[] bills) {
        int five = 0, ten = 0;
        for (int bill : bills) {
            if (bill == 5) {
                five++;
            } else if (bill == 10) {
                if (five < 1) return false;
                five--;
                ten++;
            } else {
                if(ten > 0 && five > 0) {
                    five--;
                    ten--;
                }else if(five >= 3){
                    five -= 3;
                }else return false;
            }
        }
        return true;
    }
}